package com.example.webdemo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.stream.Stream;


/**
 * @Date 2021/6/27 19:55
 * @Created by wangle
 * @Description
 */
@SpringBootTest
public class Junittest {

    @DisplayName("juint5测试")
    @Test
    public   void test1(){


        System.out.println(111);



    }
    @BeforeEach
    public  void testbefore(){


        System.out.println("测试前");
    }


    @DisplayName("断言测试")
    @Test
    public   void test3(){


       int acl=cal(2,3);
       Assertions.assertEquals(acl,5);

    }

    int cal(int a,int b){

        return a+b;
    }

    @ParameterizedTest
    @ValueSource(strings = {"one", "two", "three"})
    @DisplayName("参数化测试1")
    public void parameterizedTest1(String string) {
        System.out.println(string);
        Assertions.assertTrue(StringUtils.isNotBlank(string));
    }


    @ParameterizedTest
    @MethodSource("method")    //指定方法名
    @DisplayName("方法来源参数")
    public void testWithExplicitLocalMethodSource(String name) {
        System.out.println(name);
        Assertions.assertNotNull(name);
    }

    static Stream<String> method() {
        return Stream.of("apple", "banana");
    }

}
